import { lazyReportBatch } from '../export';

const userClick = () => {
  ['mousedown', 'touchstart'].forEach((eventType) => {
    window.addEventListener(eventType, (e) => {
      const target = e.target;
      if (target.tagName) {
        const reportData = {
          type: 'behavior',
          subType: 'click',
          target: target.tagName,
          // 用户打开网页到触发该事件的时间
          startTime: e.timeStamp,
          innerHtml: target.innerHTML,
          outerHtml: target.outerHTML,
          width: target.offsetWidth,
          height: target.offsetHeight,
          eventType: eventType,
          path: e.path,
        };
        lazyReportBatch(reportData);
      }
    });
  });
};

export default userClick;
